package com.hps.elk.controller;

import com.hps.elk.client.OrderClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author heps
 * @date 2019/11/25 21:18
 */
@RestController
@RequestMapping("/api/users")
@Slf4j
public class UserController {

    private final OrderClient orderClient;

    public UserController(OrderClient orderClient) {
        this.orderClient = orderClient;
    }

    @GetMapping("/userOrder/{id}")
    public ResponseEntity<Map<String, Object>> findUserOrder(@PathVariable("id") Long id) {
        log.debug("Request to findUserOrder: {}", id);
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", "test");
        Map<String, Object> orderMap = orderClient.findOrder(1L).getBody();
        map.put("order", orderMap);
        log.debug("Result: {}", map);
        return ResponseEntity.ok(map);
    }
}
